import nodemailder from "nodemailer";
import mailConfig from "./emailconfig"

// const mailConfig = {
//     pass: '',
//     user: '',
//     service: '',
//     host: '',
// }
function textContent(code){
    return `亲爱的 ${mailConfig.user}：\n请在验证码输入框中输入：${code}，以完成操作。\n（5分钟内有效）`
}

const transPort = nodemailder.createTransport({
    service: mailConfig.service,
    host: mailConfig.host,
    secure: true,
    auth: {
        pass: mailConfig.pass,
        user: mailConfig.user
    }
})
export async function sendEmail(to,code){
    const sendConfig = {
        to: to,
        from: mailConfig.user,
        subject: '验证码',
        text: textContent(code)
    }
    return await transPort.sendMail(sendConfig)
}
